import 'package:flutter_oldman_health/utils/http_util.dart';

import 'constant.dart';

class HealthDataService {
  //获取用户最近时间的测量数据
  static Future queryHealthData(String memberId,
      {String deviceCode, int startTime, int endTime}) async {
    var result = await HttpUtil.get(Constant.host +
        '/manager/medical/health/data/${Constant.enterpriseId}?memberId=$memberId');
    return result;
  }

  //获取血氧测量数据
  // deviceCode	否	String	 	设备串号
  // memberId	否	String	 	成员id，需要看家庭成员的数据必传
  // startTime 	否	Long	 	查询起始时间 如:1521761778301
  // endTime	否	Long	 	查询结束时间 如:1585276129191
  // limit	否	Integer	 	查询条数；不传默认所有数据，最大500
  static Future queryBloodOxygen(
      {int type = 0,
        String memberId,
        int startTime,
        int endTime}) async {
    String url = Constant.host +
        '/manager/medical/health/data/${Constant.enterpriseId}/blood_oxygen_list';
    if (type == 0) {
    } else if (type == 1) {
      url =
      '${Constant.host}/manager/medical/health/data/${Constant.enterpriseId}'
          '/blood_oxygen_list/statistics/m';
    } else if (type == 2) {
      url =
      '${Constant.host}/manager/medical/health/data/${Constant.enterpriseId}'
          '/blood_oxygen_list/statistics/y';
    }

    var result = await HttpUtil.get(url, queryParams: {
      "memberId": memberId,
      "startTime": startTime,
      "endTime": endTime,
    });
    return result;
  }

  //获取心率测量数据
  // deviceCode	否	String	 	设备串号
  // memberId	否	String	 	成员id，需要看家庭成员的数据必传
  // startTime 	否	Long	 	查询起始时间 如:1521761778301
  // endTime	否	Long	 	查询结束时间 如:1585276129191
  // limit	否	Integer	 	查询条数；不传默认所有数据，最大500
  static Future queryHeartRate(
      {int type = 0,
        String memberId,
        int startTime,
        int endTime}) async {
    String url = Constant.host +
        '/manager/medical/health/data/${Constant.enterpriseId}/heart_rate_list';
    if (type == 0) {

    } else if (type == 1) {
      url =
      '${Constant.host}/manager/medical/health/data/${Constant.enterpriseId}'
          '/heart_rate_list/statistics/m';
    } else if (type == 2) {
      url =
      '${Constant.host}/manager/medical/health/data/${Constant.enterpriseId}'
          '/heart_rate_list/statistics/y';
    }

    var result = await HttpUtil.get(url, queryParams: {
      "memberId": memberId,
      "startTime": startTime,
      "endTime": endTime,
    });
    return result;
  }

  //获取体温测量数据
  // deviceCode	否	String	 	设备串号
  // memberId	否	String	 	成员id，需要看家庭成员的数据必传
  // startTime 	否	Long	 	查询起始时间 如:1521761778301
  // endTime	否	Long	 	查询结束时间 如:1585276129191
  // limit	否	Integer	 	查询条数；不传默认所有数据，最大500
  static Future queryTemperature(
      {int type = 0,
        String memberId,
        int startTime,
        int endTime}) async {
    String url = Constant.host +
        '/manager/medical/health/data/${Constant.enterpriseId}/temperature_list';
    if (type == 0) {
    } else if (type == 1) {
      url =
      '${Constant.host}/manager/medical/health/data/${Constant.enterpriseId}'
          '/temperature_list/statistics/m';
    } else if (type == 2) {
      url =
      '${Constant.host}/manager/medical/health/data/${Constant.enterpriseId}'
          '/temperature_list/statistics/y';
    }
    var result = await HttpUtil.get(url, queryParams: {
      "memberId": memberId,
      "startTime": startTime,
      "endTime": endTime,
    });
    return result;
  }

  //获取步数测量数据
  // deviceCode	否	String	 	设备串号
  // memberId	否	String	 	成员id，需要看家庭成员的数据必传
  // startTime 	否	Long	 	查询起始时间 如:1521761778301
  // endTime	否	Long	 	查询结束时间 如:1585276129191
  // limit	否	Integer	 	查询条数；不传默认所有数据，最大500
  static Future queryStepNumber(
      {int type = 0,
        String deviceCode,
        String memberId,
        int startTime,
        int endTime}) async {
    String url = Constant.host +
        '/manager/medical/health/data/${Constant.enterpriseId}/step_number_list';
    if (type == 0) {
    } else if (type == 1) {
      url =
      '${Constant.host}/manager/medical/health/data/${Constant.enterpriseId}'
          '/step_number_list/statistics/w';
    } else if (type == 2) {
      url =
      '${Constant.host}/manager/medical/health/data/${Constant.enterpriseId}'
          '/step_number_list/statistics/y';
    }

    var result = await HttpUtil.get(url, queryParams: {
      "deviceCode": deviceCode,
      "memberId": memberId,
      "startTime": startTime,
      "endTime": endTime,
    });
    return result;
  }

  static Future sendMessage(
      String receiverId, String content, int reminderTime) async {
    var result = await HttpUtil.post(
        Constant.host + '/manager/medical/chat/${Constant.enterpriseId}',
        queryParams: {
          "receiverId": receiverId,
          "content": content,
          "reminderTime": reminderTime
        });
    return result;
  }
}
